package com.jf.identity.util;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

public class TaskUtil {

    private static ExecutorService executorService;
    private static int core = 5;
    private static int max = 10;

    static {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("task-thread-%d").build();
        BlockingDeque<Runnable> blockingDeque = new LinkedBlockingDeque<>();
        executorService = new ThreadPoolExecutor(
                core, max, 60L, TimeUnit.SECONDS, blockingDeque, threadFactory
        );
    }

    public static void submit(Runnable task) {
        if (task == null) {
            return;
        }
        executorService.submit(task);
    }

    public static void shutdown() {
        executorService.shutdown();
    }

}
